// <copyright file="IndexerTests.cs" company="Sinbadsoft">
//        Copyright (c) Sinbadsoft 2009.
//        This file is released under the terms of the
//        GNU Library General Public License (LGPL) version 2.1
//        Please refer to the "License.txt" accompanying this file.
// </copyright>
// <author>Chaker NAKHLI</author>
// <email>Chaker.Nakhli@Sinbadsoft.com</email>
// <date>2009/03/01</date>

namespace Sinbadsoft.AdvancedCollections.Tests.DynamicArray
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;

    using MbUnit.Framework;

    /// <summary>
    /// Tests the <see cref="DynamicArray{T}.Item"/> getter and setter.
    /// </summary>
    [TestFixture]
    public static class IndexerTest
    {
        private static readonly int[][] countsData = new int[][]
                            {
                                     new int[] { 1025 }, 
                                     new int[] { 33, 39 }, 
                                     new int[] { 17, 28, 16 },
                                     new int[] { 17, 9,  18, 11 },
                                     new int[] { 9,  7,  6,  5, 17 },
                                     new int[] { 3,  8,  7,  5, 11, 3 }
                             };

        [StaticTestFactory]
        public static IEnumerable<Test> BuildTests()
        {
            IList<Test> tests = new List<Test>();
            for (int i = 0; i < countsData.Length; ++i)
            {
                int[] counts = countsData[i];
                string testname = string.Format(
                    CultureInfo.InvariantCulture,
                    "Rank ({0}) Counts {1}",
                    counts.Length,
                    ArrayHelper.SequenceToString(counts));
                tests.Add(new TestCase(
                        testname,
                        delegate
                        {
                            IndexerGetAndSet(counts);
                        }));
            }

            return tests;
        }

        private static void IndexerGetAndSet(int[] counts)
        {
            Array arr = ArrayHelper.New().NewArray<object>(counts).FillWith("A").As<Array>();

            // DynamicArray elements are set using indexer set
            DynamicArray<object> dynArray = ArrayHelper.ToDynamic<object>(arr);

            // DynamicArray elements are get usting indexer get
            DynamicArrayAssert.AreElementsEqual(dynArray, arr);
        }
    }
}